const http = require("http");
const logger = require("../_unit/logs.js");

let server = http.createServer((request, response) => {
  // logger.info(request, "request");
  // logger.log(response, "response");
  /* 设置相应头 */
  response.setHeader("Content-Type", "text/html;charset=utf-8");

  /* 提取报文请求体 */
  /* 报文请求体通过 post 请求来发送 */

  let body = "";
  request.on("data", (chunk) => {
    body += chunk.toString();
  });

  request.on("end", () => {
    logger.info(body, "body");
    console.log("提取完成!");

    /* 返回响应体 */
    response.end("nodejs 服务相应体!");
  });
});

server.listen(3000, () => {
  console.log("开启3000服务!");
});
